package concurrent.spring.concurrent;

import org.springframework.lang.Nullable;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 *  FutureTask 的扩展
 */
public class ListenableFutureTask<T> extends FutureTask<T> implements ListenableFuture<T> {

    ListenableFutureCallbackRegistry<T>   callbacks=new ListenableFutureCallbackRegistry<>();

    public ListenableFutureTask(Callable<T> callable) {
        super(callable);
    }

    public ListenableFutureTask(Runnable runnable,@Nullable T result) {
        super(runnable, result);
    }

    @Override
    public void addCallback(ListenableFutureCallback<? super T> callback) {

        callbacks.addCallback(callback);
    }

    @Override
    public void addCallable(SuccessCallback<? super T> callback, FailureCallback failureCallback) {
        callbacks.addSuccessCallable(callback);
        callbacks.addFailCallable(failureCallback);

    }

    @Override
    public void done(){

    }
}
